package com.oa.entities.flows;

import com.oa.domain.UndeleteEntity;
import com.oa.entities.Department;
import com.oa.entities.Position;
import com.oa.entities.User;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "oa_app_type")
public class AppType extends UndeleteEntity<Long> {
    /**
     *
     */
    private static final long serialVersionUID = 4093396096998400677L;


    public static final String APP_TYPE_TITLE="title";

    public static final String APP_TYPE_FILETYPE="fileType";


    /** 标题 **/
    private String title;

    /** 文件状态 **/
    private int appStatus;

    /** 文件类型 **/
    private int fileType;

    /** 流程类型 **/
    private int flowType;

    /** 发布人 **/
    private User issue;

    /** 发包人的id **/
    private Long issueId;

    /** 公文类型的编号 **/
    private Long number;

    /** 监督人 **/
    private Set<User> supervisions= new HashSet<>();

    /** 模版的地址 **/
    private String filePath;

    /** 模版说明 **/
    private String context;

    /** 使用人 **/
    private Set<User> users= new HashSet<>();

    /** 使用部门 **/
    private Set<Department> departments= new HashSet<>();

    /** 使用职位 **/
    private Set<Position> positions= new HashSet<>();

    private int useType;

    @Override
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return super.getId();
    }

    @Override
    public void setId(Long id) {
        super.setId(id);
    }

    @Column(nullable = false,name = "type_title")
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column(name = "type_app_status",nullable = false,columnDefinition = "int default 0")
    public int getAppStatus() {
        return appStatus;
    }

    /**
     * 设置公文类型的状态
     *
     * @param appStatus
     *
     * @see com.oa.common.enums.AppsStatus
     */
    public void setAppStatus(int appStatus) {
        this.appStatus = appStatus;
    }

    @Column(name = "type_file_type",nullable = false)
    public int getFileType() {
        return fileType;
    }

    /**
     * @see com.oa.emuns.FileType
     * @param fileType
     */
    public void setFileType(int fileType) {
        this.fileType = fileType;
    }

    @Column(name = "file_type",nullable = false)
    public int getFlowType() {
        return flowType;
    }

    /**
     * @see com.oa.common.enums.AppsFlowType
     * @param flowType
     */
    public void setFlowType(int flowType) {
        this.flowType = flowType;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "issue_id",nullable = false,insertable = false,updatable = false)
    public User getIssue() {
        return issue;
    }

    public void setIssue(User issue) {
        this.issue = issue;
    }

    @Column(name = "issue_id")
    public Long getIssueId() {
        return issueId;
    }

    public void setIssueId(Long issueId) {
        this.issueId = issueId;
    }


    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    @Column(name = "type_context")
    public String getContext() {
        return context;
    }

    public void setContext(String context) {
        this.context = context;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "oa_apps_type_users")
    public Set<User> getUsers() {
        return users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "oa_apps_type_departments")
    public Set<Department> getDepartments() {
        return departments;
    }

    public void setDepartments(Set<Department> departments) {
        this.departments = departments;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "oa_apps_type_positions")
    public Set<Position> getPositions() {
        return positions;
    }

    public void setPositions(Set<Position> positions) {
        this.positions = positions;
    }

    @Column(name = "use_type", columnDefinition = "int default 0",nullable = false)
    public int getUseType() {
        return useType;
    }

    /**
     * @see  com.oa.common.enums.AppsUserType
     * @param useType
     */
    public void setUseType(int useType) {
        this.useType = useType;
    }

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "oa_apps_type_supervisions")
    public Set<User> getSupervisions() {
        return supervisions;
    }

    public void setSupervisions(Set<User> supervisions) {
        this.supervisions = supervisions;
    }

    @Column(name = "type_number",nullable = false,length = 32)
    public Long getNumber() {
        return number;
    }

    public void setNumber(Long number) {
        this.number = number;
    }

    @Override
    public String toString() {
        return "AppType{" +
                "title='" + title + '\'' +
                ", appStatus=" + appStatus +
                ", fileType=" + fileType +
                ", flowType=" + flowType +
                ", issue=" + issue +
                ", issueId=" + issueId +
                ", number=" + number +
                ", supervisions=" + supervisions +
                ", filePath='" + filePath + '\'' +
                ", context='" + context + '\'' +
                ", users=" + users +
                ", departments=" + departments +
                ", positions=" + positions +
                ", useType=" + useType +
                '}';
    }
}
